package com.sky.config;

import com.sky.properties.AliOssProperties;
import com.sky.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

/**
 * @author 贾晓晨
 * @version 1.0
 */
@Configuration
@Slf4j
public class AliOssConfig {
    @Autowired
    private AliOssProperties aliOssProperties;
    // 生成上传方法 并且确保唯一性
    @Bean
    @ConditionalOnMissingBean(AliOssUtil.class)
    public AliOssUtil getAliOssUtil() {
        log.info("阿里上传config{}",aliOssProperties);
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }
}
